import uni from '@dcloudio/vite-plugin-uni'
import UniHelperComponents from '@uni-helper/vite-plugin-uni-components'
import { WotResolver } from '@uni-helper/vite-plugin-uni-components/resolvers'
import UniHelperLayouts from '@uni-helper/vite-plugin-uni-layouts'
import UniHelperPages from '@uni-helper/vite-plugin-uni-pages'
import autoprefixer from 'autoprefixer'
import tailwindcss from 'tailwindcss'
import AutoImport from 'unplugin-auto-import/vite'
import { defineConfig } from 'vite'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    // https://github.com/uni-helper/vite-plugin-uni-layouts
    UniHelperLayouts(),
    // https://github.com/uni-helper/vite-plugin-uni-pages
    UniHelperPages(),
    // https://github.com/uni-helper/vite-plugin-uni-components
    UniHelperComponents({
      resolvers: [WotResolver()],
      dts: 'src/types/components.d.ts',
      directoryAsNamespace: true,
    }),
    // https://github.com/antfu/unplugin-auto-import
    AutoImport({
      include: [/\.vue$/, /\.vue\?vue/, /\.[tj]sx?$/],
      imports: ['vue', '@vueuse/core', 'uni-app'],
      dts: 'src/types/auto-imports.d.ts',
      dirs: ['src/composables', 'src/stores', 'src/utils'],
      vueTemplate: true,
      eslintrc: {
        enabled: true, // 已存在文件设置默认 false，需要更新时再打开，防止每次更新都重新生成
        filepath: './.eslintrc-auto-import.json',
      },
    }),
    uni(),
  ],

  css: {
    postcss: {
      plugins: [tailwindcss, autoprefixer],
    },
  },
})
